﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="input-ore.aspx.cs" Inherits="input_ore" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Inserimento Ore</title>
    <link href="/timereport/include/commoncss.aspx" rel="stylesheet" type="text/css" />
</head>
    <script language="JavaScript" src="/timereport/include/menu/menu_array.js" type="text/javascript"></script>
    <script language="JavaScript" src="/timereport/include/menu/mmenu.js" type="text/javascript"></script>

 <!-- Jquery per date picker  -->
  <link rel="stylesheet" href="/timereport/include/jquery/jquery-ui-1.10.3.custom.min.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script type="text/javascript" src="/timereport/include/jquery/jquery.ui.datepicker-it.js"></script>
  <script src="/timereport/include/jquery/jquery-ui-1.10.3.custom.min.js"></script>    
  <script>
      $(function () {
          $("#FVore_TBAccountingDate").datepicker($.datepicker.regional['it']);
      });
  </script>
<!-- FINE Jquery per date picker  -->

<body>

    <table width="760" border="0">
        <tr>
            <td height="30" class="BarraTop" align="right">
Utente:
                <%= Session["UserName"]  %>
            </td>
        </tr>
          <tr>
            <td height="30">&nbsp;</td>
           </tr>

    <tr><td>

    <form id="form1" class="form1" runat="server">
    <table width="60%" border="0" align="center" cellpadding="0" cellspacing="0" class="TabellaForm">
    
        <asp:FormView ID="FVore" runat="server" DataKeyNames="Hours_Id" 
            DataSourceID="DSore" EnableModelValidation="True" align="center"
            onmodechanging="FVore_modechanging" DefaultMode="Edit" 
            oniteminserted="FVore_ItemInserted" onitemupdated="FVore_ItemUpdated"
            ondatabound="FVore_DataBound">

<%--        EDIT--%>     
            <EditItemTemplate>
                <table class="TabellaForm" width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                        <th>
                            Data</th>
                        <td>
                            <asp:Label ID="LBdate" runat="server" Text='<%# Bind("Date","{0:d}") %>'></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Persona</th>
                        <td>
                            <asp:Label ID="LBperson" runat="server" Text='<%# Bind("name") %>'></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Progetto</th>
                        <td>
                            <asp:DropDownList ID="DDLprogetto" runat="server" AppendDataBoundItems="True" 
                                Width="240px" onselectedindexchanged="DDLProgetto_SelectedIndexChanged" 
                                AutoPostBack="True" CssClass="FormInput">
                            </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                ControlToValidate="DDLprogetto" Display="None" 
                                ErrorMessage="Specificare un codice progetto" InitialValue="0"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Attività</th>
                        <td>
                            <asp:DropDownList ID="DDLAttivita" runat="server" AutoPostBack="true"  AppendDataBoundItems="True" 
                                Width="240px" CssClass="FormInput">
                                <asp:ListItem Value="">-- seleziona un valore --</asp:ListItem>
                            </asp:DropDownList>
                            <asp:CustomValidator ID="CustomValidator1" runat="server" 
                                OnServerValidate="ValidaAttivita"  Display="None" 
                                ErrorMessage="Specificare un codice attività"></asp:CustomValidator>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Tipo</th>
                        <td class="style3">
                            <asp:DropDownList ID="DDLTipoora" runat="server" DataSourceID="DStipoore" 
                                DataTextField="iTipoOra" DataValueField="HourType_Id"  
                                SelectedValue='<%# Bind("HourType_Id") %>' Width="160px" 
                                CssClass="FormInput">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Ore</th>
                        <td>
                            <asp:TextBox ID="HoursTextBox" runat="server" Text='<%# Bind("Hours") %>' 
                                Columns="5" CssClass="FormInput" />
                            <asp:RangeValidator ID="RangeValidator1" runat="server" Display="None" 
                                ErrorMessage="Numero ore deve essere un valore numerico positivo" ControlToValidate="HoursTextBox" 
                                MaximumValue="999" MinimumValue="1" Type="Integer"></asp:RangeValidator>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="HoursTextBox" 
                            ErrorMessage="Numero ore deve essere un valore numerico" Display="None" ></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th>Trasferta</th>
                        <td>
                            <asp:CheckBox ID="TransferFlagCheckBox" runat="server"   
                                Checked='<%# Bind("TransferFlag") %>' />
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Storno</th>
                        <td>
                            <asp:CheckBox ID="CancelFlagCheckBox" runat="server"  
                                Checked='<%# Bind("CancelFlag") %>' />
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Nota</th>
                        <td>
                            <asp:TextBox ID="CommentTextBox" runat="server" Rows="5" 
                                Text='<%# Bind("Comment") %>' TextMode="MultiLine" Columns="50" 
                                CssClass="FormInput" />
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <asp:Label ID="LBAccountingDate" runat="server" Text="Data&nbspcompetenza"></asp:Label></th>
                        <td>
                            <asp:TextBox ID="TBAccountingDate" runat="server" Text='<%# Bind("AccountingDate", "{0:d}") %>' 
                                Columns="8" CssClass="FormInput" MaxLength="10" />
                             <asp:RangeValidator ID="RangeValidator2" runat="server" 
                                ErrorMessage="Inserire una data competenza valida" ControlToValidate="TBAccountingDate" Display="None" 
                                Type="Date" MaximumValue="31/12/9999" MinimumValue="1/1/2000" ></asp:RangeValidator>
                        </td>
                    </tr>
                    <tr>
                        <th>Creato:</th>
                        <td>
                             <asp:Label ID="LBCreationData" runat="server" Text=''></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <th>Modificato:</th>
                        <td>
                             <asp:Label ID="LBChangeData" runat="server" Text=''></asp:Label>
                        </td>
                    </tr>

                </table>
                <br>
                <table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                <td width="50%"> 
                     <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CssClass="FormButton"
                            CommandName="Update" Text="Aggiorna" /> &nbsp;
                     <asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False" 
                            CommandName="Cancel" CssClass="FormButton" Text="Annulla" /> 
                <br>
                </td>  
                </tr>
                </table>
            </EditItemTemplate>

<%--        INSERT--%> 
            <InsertItemTemplate>
             <table class="TabellaForm" width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                        <th>
                            Data</th>
                        <td>
                            <asp:Label ID="LBdate" runat="server" Text='<%# Bind("Date") %>'></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Persona</th>
                        <td>
                            <asp:Label ID="LBperson" runat="server" Text='<%# Bind("persons_id") %>'></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Progetto</th>
                        <td class="style2">
                            <asp:DropDownList ID="DDLprogetto" runat="server" AppendDataBoundItems="True"  
                                Width="240px" onselectedindexchanged="DDLProgetto_SelectedIndexChanged" 
                                AutoPostBack="True" CssClass="FormInput">
                            </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                ControlToValidate="DDLprogetto" Display="None" 
                                ErrorMessage="Specificare un codice progetto" InitialValue="0"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Attività</th>
                        <td>
                            <asp:DropDownList ID="DDLAttivita" runat="server" AutoPostBack="true"  AppendDataBoundItems="True" 
                                Width="240px" CssClass="FormInput" Visible="False">
                                <asp:ListItem Value="">--seleziona attività--</asp:ListItem>
                            </asp:DropDownList>
                            <asp:CustomValidator ID="CustomValidator1" runat="server" 
                                OnServerValidate="ValidaAttivita" Display="None" 
                                ErrorMessage="Specificare un codice attività"></asp:CustomValidator>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Tipo</th>
                        <td>
                            <asp:DropDownList ID="DDLTipoora" runat="server" DataSourceID="DStipoore" 
                                DataTextField="iTipoOra" DataValueField="HourType_Id" 
                                SelectedValue='<%# Bind("HourType_Id") %>' Width="160px" 
                                CssClass="FormInput">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <th>Ore</th>
                        <td>
                            <asp:TextBox ID="HoursTextBox" runat="server" Text='<%# Bind("Hours") %>' 
                                Columns="5" CssClass="FormInput" />
                            <asp:RangeValidator ID="RangeValidator1" runat="server"  Display="None" 
                                ErrorMessage="Numero ore deve essere un valore numerico positivo" ControlToValidate="HoursTextBox" 
                                MaximumValue="999" MinimumValue="1" Type="Integer"></asp:RangeValidator>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="HoursTextBox" Display="None"  
                            ErrorMessage="Numero ore deve essere un valore numerico"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <th>Trasferta</th>
                        <td>
                            <asp:CheckBox ID="TransferFlagCheckBox" runat="server" 
                                Checked='<%# Bind("TransferFlag") %>' />
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Storno</th>
                        <td>
                            <asp:CheckBox ID="CancelFlagCheckBox" runat="server" 
                                Checked='<%# Bind("CancelFlag") %>' />
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Nota</th>
                        <td>
                            <asp:TextBox ID="CommentTextBox" runat="server" Rows="5" 
                                Text='<%# Bind("Comment") %>' TextMode="MultiLine" Columns="50" 
                                CssClass="FormInput" />
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <asp:Label ID="LBAccountingDate" runat="server" Text="Data&nbspcompetenza"></asp:Label></th>
                        <td>
                            <asp:TextBox ID="TBAccountingDate" runat="server" Text='<%# Bind("AccountingDate") %>' 
                                Columns="8" CssClass="FormInput" MaxLength="10" />
                             <asp:RangeValidator ID="RangeValidator2" runat="server" Display="None" 
                                ErrorMessage="Inserire una data competenza valida" ControlToValidate="TBAccountingDate" 
                                Type="Date" MaximumValue="31/12/9999" MinimumValue="1/1/2000" ></asp:RangeValidator>
                        </td>
                    </tr>

                </table>
                <br>
                <table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                <td width="50%"> 
                    <asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                    Text="Crea" CssClass="FormButton" /> &nbsp;
                    <asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False"
                    CommandName="Cancel" Text="Annulla" CssClass="FormButton" />   
                <br>
                </td>  
                </tr>
                </table>
            </InsertItemTemplate>

<%--        DISPLAY--%> 
            <ItemTemplate>
            <table class="TabellaForm" width="60%" border="0" align="center" cellpadding="0" cellspacing="0"> 
                    <tr>
                        <th>
                            Data</th>
                        <td class="style2">
                            <asp:Label ID="LBdate" runat="server" Text='<%# Bind("Date","{0:d}") %>'></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Persona</th>
                        <td class="style3">
                            <asp:Label ID="LBperson" runat="server" Text='<%# Bind("name") %>'></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Progetto</th>
                        <td class="style2">
                            <asp:DropDownList ID="DDLprogetto" runat="server" AppendDataBoundItems="True" 
                                AutoPostBack="True" CssClass="FormInputDisabled" Enabled="False" 
                                onselectedindexchanged="DDLProgetto_SelectedIndexChanged" Width="240px">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Attività</th>
                        <td class="style3">
                            <asp:DropDownList ID="DDLAttivita" runat="server" AppendDataBoundItems="True" 
                                AutoPostBack="true" CssClass="FormInputDisabled" Enabled="False" Width="240px">
                                <asp:ListItem Value="">-- seleziona un valore --</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Tipo</th>
                        <td class="style3">
                            <asp:DropDownList ID="DDLTipoora" runat="server" DataSourceID="DStipoore" 
                                DataTextField="iTipoOra" DataValueField="HourType_Id" 
                                SelectedValue='<%# Bind("HourType_Id") %>' Width="160px" 
                                CssClass="FormInputDisabled" Enabled="False">
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Ore</th>
                        <td class="style3">
                            <asp:TextBox ID="HoursTextBox" runat="server" Text='<%# Bind("Hours") %>' 
                                CssClass="FormInputDisabled" Enabled="False" />
                        </td>
                    </tr>
                    <tr>
                        <th>Trasferta</th>
                        <td class="style3">
                            <asp:CheckBox ID="TransferFlagCheckBox" runat="server" 
                                Checked='<%# Bind("TransferFlag") %>' Enabled="False" />
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Storno</th>
                        <td class="style3">
                            <asp:CheckBox ID="CancelFlagCheckBox" runat="server" 
                                Checked='<%# Bind("CancelFlag") %>' Enabled="False" />
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Nota</th>
                        <td class="style3">
                            <asp:TextBox ID="CommentTextBox" runat="server" Rows="4" 
                                Text='<%# Bind("Comment") %>' TextMode="MultiLine" Columns="40" 
                                CssClass="FormInputDisabled" Enabled="False" />
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <asp:Label ID="LBAccountingDate" runat="server" Text="Data&nbspcompetenza"></asp:Label></th>
                        <td>
                           <asp:Label ID="LBAccountingDateDisplay" runat="server" Text='<%# Bind("AccountingDate","{0:d}") %>' CssClass="FormInputDisabled"></asp:Label>                          
                        </td>
                    </tr>
                    <tr>
                        <th>Creato:</th>
                        <td>
                             <asp:Label ID="LBCreationData" runat="server" Text=''></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <th>Modificato:</th>
                        <td>
                             <asp:Label ID="LBChangeData" runat="server" Text=''></asp:Label>
                        </td>
                    </tr>
                </table>
                <br>
                &nbsp;<asp:Button ID="UpdateCancelButton" runat="server" 
                    CausesValidation="False" CssClass="FormButton"
                    CommandName="Cancel" Text="Annulla" />  
                <br>
            </ItemTemplate>
      
        </asp:FormView>           
    <div>
    
        <asp:SqlDataSource ID="DSprogetti" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MSSql12155ConnectionString %>" 
            SelectCommand="SELECT Projects_Id, ProjectCode + ' ' + Name AS iProgetto FROM Projects where active = 'true' and activityON = 'true' order by ProjectCode">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="DStipoore" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MSSql12155ConnectionString %>" 
            SelectCommand="SELECT HourType_Id, HourTypeCode + ' ' + Name AS iTipoOra FROM HourType">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="DSattivita" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MSSql12155ConnectionString %>" 
            SelectCommand="SELECT Activity_id, Name + ' ' + ActivityCode AS iAttivita FROM Activity WHERE active = 'true'">
        </asp:SqlDataSource>
        <br />
    
    </div>
        <asp:SqlDataSource ID="DSore" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MSSql12155ConnectionString %>" 
                       
            SelectCommand="SELECT Hours.Hours_Id, Hours.Projects_Id, Hours.Persons_id, Hours.Date, Hours.Hours, Hours.HourType_Id, Hours.CancelFlag, Hours.Comment, Hours.TransferFlag, Hours.Activity_id, Persons.Name, CreatedBy, CreationDate, LastModifiedBy, LastModificationDate,AccountingDate FROM Hours INNER JOIN Persons ON Hours.Persons_id = Persons.Persons_id WHERE (Hours.Hours_Id = @hours_id)" 
            InsertCommand="INSERT INTO Hours(Projects_Id, Persons_id, Date, HourType_Id, Hours, CancelFlag, Comment, TransferFlag, Activity_id, CreatedBy, CreationDate, AccountingDate) VALUES (@Projects_id, @Persons_id, @Date, @HourType_id, @Hours, @CancelFlag, @Comment, @TransferFlag, @Activity_id, @CreatedBy, @CreationDate, @AccountingDate)" 
            UpdateCommand="UPDATE Hours SET Hours = @Hours, HourType_Id = @HourType_Id, CancelFlag = @CancelFlag, Comment = @Comment, TransferFlag = @TransferFlag, Activity_id = @Activity_id, Projects_Id = @Projects_Id, LastModifiedBy= @LastModifiedBy, LastModificationDate = @LastModificationDate, AccountingDate = @AccountingDate WHERE (Hours_Id = @Hours_id)" 
            oninserting="DSore_Insert_Update" onupdating="DSore_Insert_Update">
            
            <InsertParameters>
                <asp:Parameter Name="Projects_id" />
                <asp:Parameter Name="Persons_id" />
                <asp:Parameter Name="Date" />
                <asp:Parameter Name="HourType_id" />
                <asp:Parameter Name="Hours" />
                <asp:Parameter Name="CancelFlag" />
                <asp:Parameter Name="Comment" />
                <asp:Parameter Name="TransferFlag" />
                <asp:Parameter Name="Activity_id" />
                <asp:Parameter Name="CreatedBy" />
                <asp:Parameter Name="CreationDate" />
                <asp:Parameter Name="AccountingDate" />
            </InsertParameters>
            <SelectParameters>
                <asp:QueryStringParameter Name="hours_id" QueryStringField="hours_id" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="Hours" />
                <asp:Parameter Name="HourType_Id" />
                <asp:Parameter Name="CancelFlag" />
                <asp:Parameter Name="Comment" />
                <asp:Parameter Name="TransferFlag" />
                <asp:Parameter Name="Activity_id" />
                <asp:Parameter Name="Projects_Id" />
                <asp:Parameter Name="Hours_id" />
                <asp:Parameter Name="CreatedBy" />
                <asp:Parameter Name="CreationDate" />
                <asp:Parameter Name="LastModifiedBy" />
                <asp:Parameter Name="LastModificationDate" />
                <asp:Parameter Name="AccountingDate" />
            </UpdateParameters>
        </asp:SqlDataSource>

        <asp:ValidationSummary ID="ValidationSummary2" runat="server" ShowMessageBox="True" ShowSummary="false"  />
   
    </form>

    </td></tr>   
     </table>

</body>
</html>
